package baidu.com.matedemo;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.baidu.duer.libcore.util.ToastUtil;
import com.baidu.duer.smartmate.out.DuerDevice;
import com.baidu.duer.smartmate.out.WebType;

import baidu.com.matedemo.base.BaseFragment;

/**
 * Created by niufei01 on 2017/11/13.
 */

public class SinglePageFragment extends BaseFragment {

    ViewHolder viewHolder;

    @Override
    public View onCreateContentViewCompat(LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.layout_single_page, viewGroup, false);
    }

    @Override
    public void onContentViewCreated(final View view) {
        viewHolder = new ViewHolder(view);
        viewHolder.skillStoreBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra(DemoConstant.TYPE, WebType.SKILLSTORE);
                intent.putExtra(DemoConstant.EXTRA_TITLE, "技能商店");
                intent.setClass(getMActivity(), SinglePageActivity.class);
                getMActivity().startActivity(intent);
            }
        });

        viewHolder.smartHomeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra(DemoConstant.TYPE, WebType.SMARTHOME);
                intent.putExtra(DemoConstant.EXTRA_TITLE, "智能家居");
                intent.setClass(getMActivity(), SinglePageActivity.class);
                getMActivity().startActivity(intent);
            }
        });

        viewHolder.resourceBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra(DemoConstant.TYPE, WebType.RESOURCE_ACCOUNT);
                intent.putExtra(DemoConstant.EXTRA_TITLE, "资源账号");
                intent.setClass(getMActivity(), SinglePageActivity.class);
                getMActivity().startActivity(intent);
            }
        });

        viewHolder.unicastBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra(DemoConstant.TYPE, WebType.UNICAST);
                intent.putExtra(DemoConstant.EXTRA_TITLE, "娱乐广场");
                intent.setClass(getMActivity(), SinglePageActivity.class);
                getMActivity().startActivity(intent);
            }
        });

        viewHolder.orderCenterBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra(DemoConstant.TYPE, WebType.ORDER_CENTER);
                intent.putExtra(DemoConstant.EXTRA_TITLE, "订单中心");
                intent.setClass(getMActivity(), SinglePageActivity.class);
                getMActivity().startActivity(intent);
            }
        });

        viewHolder.chatFlowBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DuerDevice device = DemoApp.getInstance().getCurreDuerDevice();
                if (device == null) {
                    ToastUtil.toastWarnning(getMActivity(), "请先选定当前设备");
                    return;
                }
                Intent intent = new Intent();
                intent.putExtra(DemoConstant.TYPE, WebType.CHAT_FLOW);
                intent.putExtra(DemoConstant.EXTRA_TITLE, "对话流H5页面");
                intent.setClass(getMActivity(), SinglePageActivity.class);
                getMActivity().startActivity(intent);
            }
        });

        viewHolder.chatFlowBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DuerDevice device = DemoApp.getInstance().getCurreDuerDevice();
                if (device == null) {
                    ToastUtil.toastWarnning(getMActivity(), "请先选定当前设备");
                    return;
                }
                Intent intent = new Intent();
                intent.putExtra(DemoConstant.TYPE, WebType.CHAT_FLOW);
                intent.putExtra(DemoConstant.EXTRA_TITLE, "对话流H5页面");
                intent.setClass(getMActivity(), SinglePageActivity.class);
                getMActivity().startActivity(intent);
            }
        });

        viewHolder.xiaoduWhisperBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra(DemoConstant.TYPE, WebType.XIAODU_WHISPER);
                intent.putExtra(DemoConstant.EXTRA_TITLE, "小度密语");
                intent.setClass(getMActivity(), SinglePageActivity.class);
                getMActivity().startActivity(intent);
            }
        });

        viewHolder.duerSdkApiBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DemoIntent.intentToDuerSDKAPIIntro(getMActivity(), "DuerSDK接口");
            }
        });
    }

    public static class ViewHolder {
        public View rootView;
        public Button smartHomeBtn;
        public Button skillStoreBtn;
        public Button resourceBtn;
        public Button unicastBtn;
        public Button orderCenterBtn;
        public Button chatFlowBtn;
        public Button xiaoduWhisperBtn;
        public Button duerSdkApiBtn;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.smartHomeBtn = (Button) rootView.findViewById(R.id.btn_smarthome);
            this.skillStoreBtn = (Button) rootView.findViewById(R.id.btn_skillstore);
            this.resourceBtn = (Button) rootView.findViewById(R.id.btn_resource);
            this.unicastBtn = (Button) rootView.findViewById(R.id.btn_unicast);
            this.orderCenterBtn = (Button) rootView.findViewById(R.id.btn_order_center);
            this.chatFlowBtn = (Button) rootView.findViewById(R.id.btn_chat_flow);
            this.xiaoduWhisperBtn = (Button) rootView.findViewById(R.id.btn_xiaodu_whisper);
            this.duerSdkApiBtn = (Button) rootView.findViewById(R.id.btn_duersdk_api);
        }
    }
}
